﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Web.Zfb.bz.Gateway;

namespace PlugNT.Cms.Web.Zfb.bz
{
    public partial class Buy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            //按时构造订单号；

            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            string out_trade_no = currentTime.ToString("g");
            out_trade_no = out_trade_no.Replace("-", "");
            out_trade_no = out_trade_no.Replace(":", "");
            out_trade_no = out_trade_no.Replace(" ", "");
            //业务参数赋值；
            string gateway = T_gateway.Text;	//'支付接口
            string service = T_service.Text;
            string partner = T_partner.Text;		//partner		合作伙伴ID			保留字段
            string sign_type = T_sign_type.Text;
            string subject = T_subject.Text;	//subject		商品名称
            string body = T_body.Text;		//body			商品描述    
            string quantity = T_quantity.Text;                  //支付类型	
            string price = T_price.Text;                      //总金额					0.01～50000.00
            string show_url = T_show_url.Text;
            string seller_email = T_seller_email.Text;             //卖家账号
            string key = T_key.Text;              //partner账户的支付宝安全校验码
            string return_url = T_return_url.Text; //服务器通知返回接口
            string notify_url = T_notify_url.Text; //服务器通知返回接口
            string logistics_type = "EMS";
            string logistics_fee = TextBox1.Text;
            string logistics_payment = "SELLER_PAY";
            string logistics_type_1 = "EXPRESS";
            string logistics_fee_1 = TextBox2.Text;
            string logistics_payment_1 = "SELLER_PAY";
            string payment_type = "1";
            AliPay ap = new AliPay();
            string aliay_url = ap.CreatUrl(
                gateway,
                service,
                partner,
                sign_type,
                out_trade_no,
                subject,
                body,
                quantity,
                price,
                show_url,
                seller_email,
                key,
                return_url,
                notify_url,
                logistics_type,
                logistics_fee,
                logistics_payment,
                logistics_type_1,
                logistics_fee_1,
                logistics_payment_1,
                payment_type
                );

            //Response.Redirect(aliay_url);
            Response.Write("<form name='alipaysubmit' method='post' action='https://www.alipay.com/cooperate/gateway.do?'>");
            Response.Write("<input type='hidden' name='body' value=" + body + ">");
            Response.Write("<input type='hidden' name='logistics_fee' value=" + logistics_fee + ">");
            Response.Write("<input type='hidden' name='logistics_fee_1' value=" + logistics_fee_1 + ">");
            Response.Write("<input type='hidden' name='logistics_payment' value=" + logistics_payment + ">");
            Response.Write("<input type='hidden' name='logistics_payment_1' value=" + logistics_payment_1 + ">");
            Response.Write("<input type='hidden' name='logistics_type' value=" + logistics_type + ">");
            Response.Write("<input type='hidden' name='logistics_type_1' value=" + logistics_type_1 + ">");
            Response.Write("<input type='hidden' name='notify_url' value=" + notify_url + ">");
            Response.Write("<input type='hidden' name='out_trade_no' value=" + out_trade_no + ">");
            Response.Write("<input type='hidden' name='partner' value=" + partner + ">");
            Response.Write("<input type='hidden' name='payment_type' value=" + payment_type + ">");
            Response.Write("<input type='hidden' name='price' value=" + price + ">");
            Response.Write("<input type='hidden' name='quantity' value=" + quantity + ">");
            Response.Write("<input type='hidden' name='return_url' value=" + return_url + ">");
            Response.Write("<input type='hidden' name='seller_email' value=" + seller_email + ">");
            Response.Write("<input type='hidden' name='service' value=" + service + ">");
            Response.Write("<input type='hidden' name='show_url' value=" + show_url + ">");
            Response.Write("<input type='hidden' name='subject' value=" + subject + ">");
            Response.Write("<input type='hidden' name='sign' value=" + aliay_url + ">");
            Response.Write("<input type='hidden' name='sign_type' value=" + sign_type + ">");
            Response.Write("</form>");
            Response.Write("<script>");
            Response.Write("document.alipaysubmit.submit()");
            Response.Write("</script>");

        }
    }
}
